<template>
  <div class="customer-service">
    <!-- 主内容区 -->
    <div class="service-container">
      <!-- 左侧联系信息 -->
      <div class="contact-info">
        <h3 class="section-title">联系方式</h3>

        <p class="service-desc">
          如有任何问题或建议，请通过以下方式联系我们，我们将尽快为您解答
        </p>

        <!-- 联系方式列表 -->
        <ul class="contact-list">
<!--          <li class="contact-item">
            <i class="contact-icon fa-qq"></i>
            <div class="contact-detail">
              <span class="contact-label">QQ</span>
              <span class="contact-value">2825449628</span>
              <button class="copy-btn" @click="copyText('2825449628', 'QQ号码')">
                <i class="copy-icon"></i> 复制
              </button>
            </div>
          </li>-->

          <li class="contact-item">
            <i class="contact-icon fa-weixin"></i>
            <div class="contact-detail">
              <span class="contact-label">微信</span>
              <span class="contact-value">liujijiselfwechat</span>
              <button class="copy-btn" @click="copyText('liujijiselfwechat', '微信号')">
                <i class="copy-icon"></i> 复制
              </button>
            </div>
          </li>

          <li class="contact-item">
            <i class="contact-icon fa-envelope"></i>
            <div class="contact-detail">
              <span class="contact-label">邮箱</span>
              <div class="email-values">
                <span class="contact-value">liujijiself@gmail.com</span>
                <button class="copy-btn" @click="copyText('liujijiself@gmail.com', '邮箱地址')">
                  <i class="copy-icon"></i> 复制
                </button>
              </div>
              <div class="email-values">
                <span class="contact-value">liujijiself@163.com</span>
                <button class="copy-btn" @click="copyText('liujijiself@163.com', '邮箱地址')">
                  <i class="copy-icon"></i> 复制
                </button>
              </div>
            </div>
          </li>

          <li class="contact-item">
            <i class="contact-icon fa-globe"></i>
            <div class="contact-detail">
              <span class="contact-label">官网</span>
              <a href="https://liujijiself.com" target="_blank" class="contact-value link">
                liujijiself.com
              </a>
              <button class="copy-btn" @click="copyText('https://liujijiself.com', '官网地址')">
                <i class="copy-icon"></i> 复制
              </button>
            </div>
          </li>
        </ul>

        <div class="service-hours">
          <h4 class="hours-title">服务时间</h4>
          <p class="hours-content">周一至周日 9:00-21:00（节假日不休）</p>
        </div>
      </div>

      <!-- 右侧微信二维码 -->
      <div class="wechat-qr">
        <div class="qr-container">
          <!-- 二维码图片 -->
          <img
            src="@/assets/customer_service.png"
            alt="微信客服二维码"
            class="qr-img"
          >
        </div>

        <p class="qr-desc">扫码添加微信客服</p>
      </div>
    </div>

    <!-- 页脚 -->
    <span>
      <a :href="baseDomain" target="_blank">泡芙工作室</a>
    </span>

    <!-- Toast 提示 -->
    <div class="toast" :class="{ 'toast-show': showToast }">
      <i class="toast-icon" :class="toastType === 'success' ? 'icon-success' : 'icon-warning'"></i>
      <span class="toast-text">{{ toastMessage }}</span>
    </div>
  </div>
</template>

<script>

export default {
  name: 'CustomerService',
  data() {
    return {
      baseDomain: process.env.VUE_APP_FILE_PORT,
      showToast: false,
      toastMessage: '',
      toastType: 'success'
    }
  },
  methods: {
    // 复制文本到剪贴板
    copyText(text, type) {
      if (navigator.clipboard && navigator.clipboard.writeText) {
        navigator.clipboard.writeText(text)
          .then(() => this.showToastMessage(`${type}已复制到剪贴板`))
          .catch(() => this.fallbackCopy(text, type))
      } else {
        this.fallbackCopy(text, type)
      }
    },
    // 降级复制方案
    fallbackCopy(text, type) {
      const ta = document.createElement('textarea')
      ta.value = text
      ta.style.position = 'fixed'
      document.body.appendChild(ta)
      ta.select()
      try {
        document.execCommand('copy')
        this.showToastMessage(`${type}已复制到剪贴板`)
      } catch (e) {
        this.showToastMessage(`复制失败，请手动复制：${text}`, 'warning')
      }
      document.body.removeChild(ta)
    },
    // 显示Toast提示
    showToastMessage(message, type = 'success') {
      this.toastMessage = message
      this.toastType = type
      this.showToast = true
      setTimeout(() => {
        this.showToast = false
      }, 3000)
    }
  }
}
</script>

<style scoped>
.customer-service {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.service-container {
  display: flex;
  gap: 40px;
  width: 100%;
  max-width: 900px;
  margin-bottom: 10px;
}

/* 左侧联系信息样式 */
.contact-info {
  flex: 1 1 60%;
  background-color: #ffffff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.section-title {
  margin: 0 0 20px;
  font-size: 20px;
  color: #2d3748;
  font-weight: 600;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf2f7;
}

.service-desc {
  margin: 0 0 25px;
  color: #718096;
  line-height: 1.6;
  font-size: 14px;
}

.contact-list {
  list-style: none;
  padding: 0;
}

.contact-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #f7fafc;
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-icon {
  font-size: 20px;
  color: #3182ce;
  margin-right: 15px;
  margin-top: 3px;
  width: 24px;
  text-align: center;
}

.contact-detail {
  flex: 1;
}

.contact-label {
  display: inline-block;
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 6px;
  margin-right: 10px;
  font-size: 15px;
}

.contact-value {
  display: inline-block;
  color: #4a5568;
  font-size: 14px;
  word-break: break-all;
}

.link {
  color: #3182ce;
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
  background-color: #f7fafc;
  color: #4a5568;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 10px;
}

.copy-btn:hover {
  background-color: #edf2f7;
  border-color: #cbd5e0;
}

.copy-icon::before {
  content: "📋";
  font-size: 12px;
}

.email-values {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.service-hours {
  background-color: #f7fafc;
  padding: 15px;
  border-radius: 8px;
}

.hours-title {
  margin: 0 0 8px;
  font-size: 15px;
  color: #2d3748;
  font-weight: 600;
}

.hours-content {
  margin: 0;
  color: #718096;
  font-size: 14px;
}

/* 右侧微信二维码样式 */
.wechat-qr {
  width: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-container {
  width: 220px;
  height: 220px;
  background-color: #ffffff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 15px;
}

.qr-img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border-radius: 6px;
}

.qr-desc {
  font-size: 16px;
  font-weight: 500;
  margin: 0 0 10px;
  text-align: center;
}

/* Toast 提示样式 */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -100px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  background-color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast-show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast-icon {
  font-size: 16px;
}

.icon-success::before {
  content: "✓";
  color: #38a169;
}

.icon-warning::before {
  content: "!";
  color: #ecc94b;
}

.toast-text {
  font-size: 14px;
  color: #2d3748;
}
</style>
